package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.smedi.ismedi.inmail.api.dto.request.safetyBoard.*;
import com.smedi.ismedi.inmail.api.dto.response.safetyBoard.*;
import com.smedi.ismedi.inmail.api.feign.RemoteSafetyBoardFeignApi;
import com.smedi.ismedi.inmail.core.application.command.*;
import com.smedi.ismedi.inmail.core.application.query.SafetyBoardQueryService;
import com.smedi.ismedi.inmail.core.application.query.vo.*;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@EnableScheduling
public class SafetyBoardController implements RemoteSafetyBoardFeignApi {
    private final SafetyBoardQueryService safetyBoardQueryService;
    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<SafetyBoardOverviewResponse> getSafetyBoardOverview() {
        SafetyBoardOverviewVo safetyBoardOverview = safetyBoardQueryService.getSafetyBoardOverview();
        return new ResponseData<>().success(adapterConverter.safetyBoardOverviewVoToSafetyBoardOverviewResponse(safetyBoardOverview));
    }

    @Override
    public ResponseData<LaborStatisticsResponse> getLaborStatistics() {
        LaborStatisticsVo laborStatistics = safetyBoardQueryService.getLaborStatistics();
        return new ResponseData<>().success(adapterConverter.laborStatisticsVoToLaborStatisticsResponse(laborStatistics));
    }

    @Override
    public ResponseData<HiddenDangerStatisticsResponse> getHiddenDangerStatistics(HiddenDangerStatisticsRequest hiddenDangerStatisticsRequest) {
        HiddenDangerStatisticsCommand hiddenDangerStatisticsCommand = adapterConverter.hiddenDangerStatisticsRequestToHiddenDangerStatisticsCommand(hiddenDangerStatisticsRequest);
        HiddenDangerStatisticsVo hiddenDangerStatistics = safetyBoardQueryService.getHiddenDangerStatistics(hiddenDangerStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.hiddenDangerStatisticsVoToHiddenDangerStatisticsResponse(hiddenDangerStatistics));
    }

    @Override
    public ResponseData<MajorHazardPaginationData> getTodayMajorHazardPage(MajorHazardTodayPageRequest majorHazardTodayPageRequest) {
        MajorHazardTodayPageCommand majorHazardTodayPageCommand = adapterConverter.majorHazardTodayPageRequestToMajorHazardTodayPageCommand(majorHazardTodayPageRequest);
        MajorHazardPageVo todayMajorHazardPage = safetyBoardQueryService.getTodayMajorHazardPage(majorHazardTodayPageCommand);
        return new ResponseData<>().success(adapterConverter.majorHazardPageVoToMajorHazardPaginationData(todayMajorHazardPage));
    }

    @Override
    public ResponseData<DangerSourcePaginationData> getTodayDangerSourcePage(DangerSourceTodayPageRequest dangerSourceTodayPageRequest) {
        DangerSourceTodayPageCommand dangerSourceTodayPageCommand = adapterConverter.dangerSourceTodayPageRequestToDangerSourceTodayPageCommand(dangerSourceTodayPageRequest);
        DangerSourcePageVo dangerSourcePage = safetyBoardQueryService.getTodayDangerSourcePage(dangerSourceTodayPageCommand);
        return new ResponseData<>().success(adapterConverter.dangerSourcePageVoToDangerSourcePaginationData(dangerSourcePage));
    }

    @Override
    public ResponseData<ProjectStatisticsResponse> getProjectStatistics() {
        ProjectStatisticsVo projectStatisticsVo = safetyBoardQueryService.getProjectStatistics();
        return new ResponseData<>().success(adapterConverter.projectStatisticsVoToProjectStatisticsResponse(projectStatisticsVo));
    }

    @Override
    public ResponseData<ProjectStatisticsByRegionResponse> getProjectStatisticsByRegion(String provinceName) {
        ProjectStatisticsByRegionVo projectStatisticsByRegionVo = safetyBoardQueryService.getProjectStatisticsByRegion(provinceName);
        return new ResponseData<>().success(adapterConverter.projectStatisticsByRegionVoToProjectStatisticsByRegionResponse(projectStatisticsByRegionVo));
    }

    @Override
    public ResponseData<List<StatisticsNodeResponse>> getSafetyCheckInstituteStatics(SafetyCheckInstituteStatisticsRequest safetyCheckInstituteStatisticsRequest) {
        SafetyCheckInstituteStatisticsCommand safetyCheckInstituteStatisticsCommand = adapterConverter.safetyCheckInstituteStatisticsRequestToSafetyCheckStatisticsCommand(safetyCheckInstituteStatisticsRequest);
        List<StatisticsNodeVo> statisticsNodeVos = safetyBoardQueryService.getSafetyCheckInstituteStatics(safetyCheckInstituteStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.statisticsNodeVoToStatisticsNodeResponse(statisticsNodeVos));
    }

    @Override
    public ResponseData<List<StatisticsNodeResponse>> getSafetyCheckOrganizationStatics(SafetyCheckOrganizationStatisticsRequest safetyCheckOrganizationStatisticsRequest) {
        SafetyCheckOrganizationStatisticsCommand safetyCheckOrganizationStatisticsCommand = adapterConverter.safetyCheckOrganizationStatisticsRequestToSafetyCheckStatisticsCommand(safetyCheckOrganizationStatisticsRequest);
        List<StatisticsNodeVo> statisticsNodeVos = safetyBoardQueryService.getSafetyCheckOrganizationStatics(safetyCheckOrganizationStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.statisticsNodeVoToStatisticsNodeResponse(statisticsNodeVos));
    }

    @Override
    public ResponseData<List<StatisticsNodeResponse>> getHiddenDangerInstituteStatics(HiddenDangerInstituteStatisticsRequest hiddenDangerInstituteStatisticsRequest) {
        HiddenDangerInstituteStatisticsCommand hiddenDangerInstituteStatisticsCommand = adapterConverter.hiddenDangerInstituteStatisticsRequestToHiddenDangerStatisticsCommand(hiddenDangerInstituteStatisticsRequest);
        List<StatisticsNodeVo> statisticsNodeVos = safetyBoardQueryService.getHiddenDangerInstituteStatics(hiddenDangerInstituteStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.statisticsNodeVoToStatisticsNodeResponse(statisticsNodeVos));
    }

    @Override
    public ResponseData<List<StatisticsNodeResponse>> getHiddenDangerOrganizationStatics(HiddenDangerOrganizationStatisticsRequest hiddenDangerOrganizationStatisticsRequest) {
        HiddenDangerOrganizationStatisticsCommand hiddenDangerOrganizationStatisticsCommand = adapterConverter.hiddenDangerStatisticsRequestToHiddenDangerStatisticsCommand(hiddenDangerOrganizationStatisticsRequest);
        List<StatisticsNodeVo> statisticsNodeVos = safetyBoardQueryService.getHiddenDangerOrganizationStatics(hiddenDangerOrganizationStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.statisticsNodeVoToStatisticsNodeResponse(statisticsNodeVos));
    }

    public ResponseData<List<HiddenDangerProjectStatisticsResponse>> getHiddenDangerProjectStatics(HiddenDangerStatisticsProjectRequest hiddenDangerStatisticsProjectRequest) {
        HiddenDangerProjectStatisticsCommand hiddenDangerProjectStatisticsCommand = adapterConverter.hiddenDangerStatisticsProjectRequestToHiddenDangerStatisticsProjectCommand(hiddenDangerStatisticsProjectRequest);
        List<HiddenDangerProjectStatisticsVo> hiddenDangerProjectStatisticsVos = safetyBoardQueryService.getHiddenDangerProjectStatics(hiddenDangerProjectStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.hiddenDangerStatisticsInProjectVoToHiddenDangerStatisticsInProjectResponse(hiddenDangerProjectStatisticsVos));
    }

    @Override
    public ResponseData<List<SafetyCheckProjectStatisticsResponse>> getSafetyCheckProjectStatics(SafetyCheckStatisticsProjectRequest safetyCheckStatisticsProjectRequest) {
        SafetyCheckProjectStatisticsCommand safetyCheckProjectStatisticsCommand = adapterConverter.safetyCheckStatisticsProjectRequestToSafetyCheckStatisticsProjectCommand(safetyCheckStatisticsProjectRequest);
        List<SafetyCheckProjectStatisticsVo> safetyCheckProjectStatisticsVos = safetyBoardQueryService.getSafetyCheckProjectStatics(safetyCheckProjectStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.safetyCheckStatisticsInProjectVoToSafetyCheckStatisticsInProjectResponse(safetyCheckProjectStatisticsVos));
    }

    @Override
    public ResponseData<List<SafetyEducationProjectStatisticsResponse>> getSafetyEducationProjectStatics(SafetyEducationStatisticsProjectRequest safetyEducationStatisticsProjectRequest) {
        SafetyEducationProjectStatisticsCommand safetyEducationProjectStatisticsCommand = adapterConverter.safetyEducationStatisticsProjectRequestToSafetyEducationStatisticsProjectCommand(safetyEducationStatisticsProjectRequest);
        List<SafetyEducationProjectStatisticsVo> safetyEducationProjectStatisticsVos = safetyBoardQueryService.getSafetyEducationProjectStatics(safetyEducationProjectStatisticsCommand);
        return new ResponseData<>().success(adapterConverter.safetyEducationStatisticsInProjectVoToSafetyEducationStatisticsInProjectResponse(safetyEducationProjectStatisticsVos));
    }
}
